﻿using System.Web.UI;
using Microsoft.Practices.ServiceLocation;

namespace Pap.Web.Utils
{
    /// <summary>
    /// 
    /// </summary>
    public interface IViewModel
    {
    }
    //-----------------------------------------------
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BasePage<T> : Page where T : IViewModel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BasePage&lt;T&gt;"/> class.
        /// </summary>
        public BasePage()
        {
            this.ViewModel = ServiceLocator.Current.GetInstance<T>();
        }
        /// <summary>
        /// Gets or sets the view data.
        /// </summary>
        /// <value>
        /// The view data.
        /// </value>
        protected T ViewModel
        {
            get;
            set;
        }
    }
    //------------------------------------------------
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BaseUserControl<T> : UserControl where T : IViewModel
    {
        /// <summary>
        /// Gets or sets the view model.
        /// </summary>
        /// <value>
        /// The view model.
        /// </value>
        protected T ViewModel { set; get; }

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseUserControl&lt;T&gt;"/> class.
        /// </summary>
        public BaseUserControl()
        {
            this.ViewModel = ServiceLocator.Current.GetInstance<T>();
        }
    }
}
